Computer programs are typically written in a high level language that allows the user a wide range of instructions and freedom to write code that contains relatively few restrictions. Many programs rely on libraries of classes that are written by third parties. The programmer typically uses these routines directly or writes a sub-class of a class in the library. The author of the library routines has no control over the code that is written in the sub-class defined by the programmer using the library.
As computer programs become more complex, there are increasingly situations in which it is useful to restrict at least a portion of the code that can be written to a subset of the more general language. For example, consider a program that contains two threads that run in parallel on the computer. Consider a case in which the two threads use the same global variable within each thread, and that variable can be changed during the execution of the threads. Problems can arise if one of the threads assumes that the value of the variable is constant over the execution of that thread, since the thread cannot detect the change in the variable. The language in which the threads are written typically allows the programmer to write code that assumes that the variable is constant over the execution of the thread. Such code is clearly dangerous in the context of two parallel operating threads. Hence, it would be advantageous to restrict the code that can be written in this case to code that does not depend on a global variable remaining constant during the execution of the threads. For example, the code could be restricted such that it is not allowed to refer to any non-constant global variable in the sub-classes that execute parallel threads.
In general, the programmer is presented with a library that includes a collection of classes. The programmer either uses this library directly or defines sub-classes of the classes in the library. As noted above, the author of the library has no control over the code in the sub-classes. However, if a sub-class fails, the author of the library is often viewed as sharing the blame. Hence, it would be advantageous to provide a mechanism for enforcing a set of language restrictions on code that uses the library or sub-classes of that library.